463C - Gargari and Bishops - CodeForces Solution


greedy hashing implementation *1900

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <cstdio>
using namespace std;
__int64 n,t,r,a[2001][2001],v1[2001<<1],v2[2001<<1],x[]={1,2},y[]={1,1},p[2];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%I64d",&a[i][j]),v1[i+j]+=a[i][j],v2[i-j+n]+=a[i][j];
    for(int i=0;i<n;i++) for(int j=0;j<n;j++){
      t=(i+j)&1;
      r=v1[i+j]-a[i][j]+v2[i-j+n];
      if(r>p[t])x[t]=i+1,y[t]=j+1,p[t]=r;
    }
    printf("%I64d\n%I64d %I64d\n%I64d %I64d",p[0]+p[1],x[0],y[0],x[1],y[1]);
    return 0;
}


Comments

Submit
0 Comments
More Questions

583. Delete Operation for Two Strings
518. Coin Change 2
516. Longest Palindromic Subsequence
468. Validate IP Address
450. Delete Node in a BST
445. Add Two Numbers II
442. Find All Duplicates in an Array
437. Path Sum III
436. Find Right Interval
435. Non-overlapping Intervals
406. Queue Reconstruction by Height
380. Insert Delete GetRandom O(1)
332. Reconstruct Itinerary
368. Largest Divisible Subset
377. Combination Sum IV
322. Coin Change
307. Range Sum Query - Mutable
287. Find the Duplicate Number
279. Perfect Squares
275. H-Index II
274. H-Index
260. Single Number III
240. Search a 2D Matrix II
238. Product of Array Except Self
229. Majority Element II
222. Count Complete Tree Nodes
215. Kth Largest Element in an Array
198. House Robber
153. Find Minimum in Rotated Sorted Array
150. Evaluate Reverse Polish Notation